<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组</title>
    <script src="js/traceur.js"></script>
    <script src="js/bootstrap.js"></script>
    <script type="module">
        let str = "0123";
        let obj = {number: 1};
        let arr = Array.from(str, function (value) {
            return parseInt(value) + this.number;
        }, obj);
        console.log(arr); //Array 1, 2, 3, 4


        let arr12 = new Array(2);
        let arr22 = Array.of(2);
        console.log(arr12[0], arr12.length); //undefined, 2
        console.log(arr22[0], arr22.length); //2, 1

        let arr1 = [1, 2, 3, 4];
        let arr2 = [1, 2, 3, 4];
        let arr3 = [1, 2, 3, 4];
        let arr4 = [1, 2, 3, 4];
        let arr5 = [1, 2, 3, 4];
        arr1.fill(5);
        arr2.fill(5, 1, 2);
        arr3.fill(5, 1, 3);
        arr4.fill(5, -3, 2);
        arr5.fill(5, 0, -2);
        console.log(arr1); //5, 5, 5, 5
        console.log(arr2); //1, 5, 3, 4
        console.log(arr3); //1, 5, 5, 4
        console.log(arr4); //1, 5, 3, 4
        console.log(arr5); //5, 5, 3, 4


        var x = 12;
        var array = [11, 12, 13];
        var result = array.find(function (value, index, array) {
            if (value == this) {
                return true;
            }
        }, x);
        console.log(result); // 12

        let x1 = 12;
        let array1 = [11, 12, 13];
        let result1 = array1.findIndex(function (value, index, array) {
            if (value == this) {
                return true;
            }
        }, x1);
        console.log(result1);  // 1(索引号）



        let arr13 = [1, 2, 3, 4, 5];
        let arr23 = [1, 2, 3, 4, 5];
        let arr33 = [1, 2, 3, 4, 5];
        let arr43 = [1, 2, 3, 4, 5];
        arr13.copyWithin(1, 2, 4);
        arr23.copyWithin(0, 1);
        arr33.copyWithin(1, -2);
        arr43.copyWithin(1, -2, -1);
        console.log(arr13); //1, 3, 4, 4, 5
        console.log(arr23); // 2, 3, 4, 5, 5
        console.log(arr33); // 1, 4, 5, 4, 5
        console.log(arr43); // 1, 4, 3, 4, 5

        //读取数组的索引跟值
        let array2 = ['a', 'b', 'c'];
        let entries = array2.entries();
        let keys = array2.keys();
        let values = array2.values();
        console.log(...entries); // 0,a 1,b 2,c
        console.log(...keys); //0, 1, 2
        console.log(...values); // a, b, c

    </script>
</head>
<body>

</body>
</html>